import numpy as np
import pandas as pd
from fbprophet import Prophet
from matplotlib import pyplot as plt
df = pd.read_csv("Kaggle/AvocadoPrices/input/avocado.csv")

df.head()

df['Date'] = pd.to_datetime(df['Date'])

num_list_items = 10
regions = df.groupby(df.region)
print("Total regions : ",len(regions))
print("Print first ", num_list_items, " regions.")
for name,group in regions:
    print(name," : ",len(group))
    num_list_items -=1
    if num_list_items==0:break

PREDICTING_FOR = "TotalUS"
date_price = regions.get_group(PREDICTING_FOR)[['Date','AveragePrice']].reset_index(drop=True)

date_price.plot(x='Date',y='AveragePrice',kind='line')

date_price = date_price.rename(columns={'Date':'ds','AveragePrice':'y'})

m = Prophet()
m.fit(date_price)

future = m.make_future_dataframe(periods=365)
forecast = m.predict(future)
forecast.tail()

fig1 = m.plot(forecast)

fig2 = m.plot_components(forecast)

